package com.qf.web.sys_role_menu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qf.web.sys_role_menu.entity.RoleMenu;
import com.qf.web.sys_role_menu.mapper.RoleMenuMapper;
import com.qf.web.sys_role_menu.service.RoleMenuService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author xufuhan
 * @Date 2024/9/11 11:29
 */

@Service
public class RoleMenuServiceImpl extends ServiceImpl<RoleMenuMapper, RoleMenu> implements RoleMenuService {
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void saveRoleMenu(Long roleId, List<Long> menuIds) {
        //先删除角色旧的id，在重新插入
        QueryWrapper<RoleMenu> wrapper=new QueryWrapper<>();
        wrapper.lambda().eq(RoleMenu::getRoleId,roleId);
        this.baseMapper.delete(wrapper);

        //插入
        this.baseMapper.saveRoleMenu(roleId, menuIds);
    }
}
